/*-----------------------------------------------------
 * 权限子系统-锁定用户模块
 * ---------------------------------------------------*/
jx.ready(function () {
    //定义变量
    var api = {
        grid: '/sys/lockUser/grid',
        remove: '/sys/lockUser/remove',
        details: '/sys/lockUser/details'
    };
    var $grid = $('#grid'), $gridform = $('#gridform');
    var gridInstance;
    // var dialogWidth = $grid.data('dialogWidth'),
    //     dialogHeight = $grid.data('dialogHeight');
    var detailsTitle = '查看锁定用户';
    var gridUrl = jx.apiUrl(api.grid),
        removeUrl = jx.apiUrl(api.remove),
        detailsUrl = jx.apiUrl(api.details);

    //初始化表格
    var initGrid = function () {
        gridInstance = $grid.jxgrid({
            url: gridUrl,
            onDblClickRow: function (index, row) {
                detailsData(row);
            }
        });
        $grid.datagrid('getPager').pagination({
            layout:['info'],
            displayMsg : '共{total}条记录'
        });
    };

    //初始化事件
    var initEvent = function () {
        $('#btn-remove').click(function () {
            removeData();
        });
    };

    //注销
    var removeData = function () {
        if (!gridInstance.hasCheckedRow()) return;
        var ids = gridInstance.getCheckedRowIds();
        jx.ajax({
            url: removeUrl,
            data: {ids: ids.join()},
            confirm: '注：您确定要移除吗？',
            maskMsg: '正在移除,请稍等...',
            success: function (result) {
                gridInstance.reloadGridData();
                jx.toastr.success('移除成功');
            }
        });
    };

    //查看数据
    var detailsData = function (row) {
        jx.auth.detailsData(gridInstance,row,{
            title: detailsTitle,
            url: detailsUrl
        });
    };

    //定义表格列格式化函数

    //对外接口 重新加载表格数据
    window.reloadGridData = function () {
        gridInstance.reloadGridData();
    };

    //初始化
    initGrid();
    initEvent();
});